{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "61e29120",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-03-02T02:22:23.780769Z",
     "start_time": "2023-03-02T02:22:23.774767Z"
    }
   },
   "source": [
    "2023-02-26\n",
    "\n",
    "Python Data Analysis Course(PDAC）\n",
    "\n",
    "记录人：吴粤"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d359b8a",
   "metadata": {},
   "source": [
    "# jupyter notebook键盘快捷键\n",
    "*******"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "65bd86c2",
   "metadata": {},
   "source": [
    "## 进入命令模式之后（此时你没有活跃单元），你可以尝试以下快捷键"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4fb5d901",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-03-02T02:31:42.833896Z",
     "start_time": "2023-03-02T02:31:42.819151Z"
    }
   },
   "source": [
    "* A 会在活跃单元之上插入一个新的单元，B 会在活跃单元之下插入一个新单元。\n",
    "* 连续按两次 D，可以删除一个单元。\n",
    "* 撤销被删除的单元，按 Z。\n",
    "* Y 会将当前活跃的单元变成一个代码单元。\n",
    "* 按住 Shift +上或下箭头可选择多个单元。在多选模式时，按住 Shift + M 可合并你的选择。\n",
    "* 按 F 会弹出「查找和替换」菜单。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70b72102",
   "metadata": {},
   "source": [
    "## 处于编辑模式时（在命令模式时按 Enter 会进入编辑模式），你会发现下列快捷键很有用："
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f8dc69cf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-03-02T02:45:36.556261Z",
     "start_time": "2023-03-02T02:45:36.538346Z"
    }
   },
   "source": [
    "* Ctrl + Home 到达单元起始位置。\n",
    "* Ctrl + S 保存进度。\n",
    "* 如之前提到的，Ctrl + Enter 会运行你的整个单元块。\n",
    "* Alt + Enter 不止会运行你的单元块，还会在下面添加一个新单元。\n",
    "* Ctrl + Shift + F 打开命令面板。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a17f60c",
   "metadata": {},
   "source": [
    "# Python 基础回顾（预备知识）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa5b097e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-03-02T02:47:24.394386Z",
     "start_time": "2023-03-02T02:47:24.379497Z"
    }
   },
   "source": [
    "## 列表推导式与条件赋值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "621a599d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-03-02T02:47:53.991284Z",
     "start_time": "2023-03-02T02:47:53.979361Z"
    }
   },
   "outputs": [],
   "source": [
    "student_index = [100001,100002,100003,100004,100005,100006]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a94310c2",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-03-02T02:48:13.760889Z",
     "start_time": "2023-03-02T02:48:13.748790Z"
    }
   },
   "outputs": [],
   "source": [
    "# 需求： 学号 奇数先筛选出来"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d4ef949b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-03-02T02:49:07.642756Z",
     "start_time": "2023-03-02T02:49:07.634671Z"
    }
   },
   "outputs": [],
   "source": [
    "奇数_students = []\n",
    "for i in student_index:\n",
    "    if i%2 != 0:\n",
    "        奇数_students.append(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d940d03f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-03-02T02:49:15.420676Z",
     "start_time": "2023-03-02T02:49:15.400672Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[100001, 100003, 100005]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "奇数_students"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "f968cadd",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-03-02T02:49:27.293579Z",
     "start_time": "2023-03-02T02:49:27.274586Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[100001, 100003, 100005]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表推导式---> [结果变量  for循环 循环体]  ==> 一切的循环都可以用推导式来写\n",
    "奇数_students = [i for i in student_index if i%2 !=0] \n",
    "奇数_students "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "9fa5c46e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-03-02T02:49:36.683125Z",
     "start_time": "2023-03-02T02:49:36.672535Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a_c', 'a_d', 'b_c', 'b_d']"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 课本的例子\n",
    "results = [m+'_'+n for m in ['a','b'] for n in ['c','d']] \n",
    "results "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "2cce7d9d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-03-02T02:49:48.329446Z",
     "start_time": "2023-03-02T02:49:48.312526Z"
    }
   },
   "outputs": [],
   "source": [
    "results = []\n",
    "for m in ['a','b']:\n",
    "    for n in ['c','d']:\n",
    "        results.append(m+'_'+n) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c7dcddcb",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-03-02T02:49:50.114200Z",
     "start_time": "2023-03-02T02:49:50.096590Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a_c', 'a_d', 'b_c', 'b_d']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "49f72c4b",
   "metadata": {},
   "source": [
    "## 文件的读取和写入（P27）"
   ]
  },
  {
   "cell_type": "raw",
   "id": "a18a6cfa",
   "metadata": {},
   "source": [
    "·1.csv\n",
    "·2.excel\n",
    "·3.text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "83625185",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-03-02T02:54:22.522486Z",
     "start_time": "2023-03-02T02:54:22.507570Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "5bab3e69",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-03-02T02:54:42.230447Z",
     "start_time": "2023-03-02T02:54:37.446077Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>排名</td>\n",
       "      <td>排名变化</td>\n",
       "      <td>企业</td>\n",
       "      <td>价值（亿元人民币）</td>\n",
       "      <td>价值变化（亿元人民币）</td>\n",
       "      <td>总部</td>\n",
       "      <td>行业</td>\n",
       "      <td>成立年份</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>抖音</td>\n",
       "      <td>13400</td>\n",
       "      <td>-10050</td>\n",
       "      <td>北京</td>\n",
       "      <td>社交媒体</td>\n",
       "      <td>2012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>SpaceX</td>\n",
       "      <td>8400</td>\n",
       "      <td>1680</td>\n",
       "      <td>洛杉矶</td>\n",
       "      <td>航天</td>\n",
       "      <td>2002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>-1</td>\n",
       "      <td>蚂蚁集团</td>\n",
       "      <td>8000</td>\n",
       "      <td>-2010</td>\n",
       "      <td>杭州</td>\n",
       "      <td>金融科技</td>\n",
       "      <td>2014</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>Stripe</td>\n",
       "      <td>4100</td>\n",
       "      <td>-2230</td>\n",
       "      <td>旧金山</td>\n",
       "      <td>金融科技</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>11</td>\n",
       "      <td>Shein</td>\n",
       "      <td>4000</td>\n",
       "      <td>2680</td>\n",
       "      <td>广州</td>\n",
       "      <td>电子商务</td>\n",
       "      <td>2012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>15</td>\n",
       "      <td>币安</td>\n",
       "      <td>3000</td>\n",
       "      <td>2010</td>\n",
       "      <td>马耳他</td>\n",
       "      <td>区块链</td>\n",
       "      <td>2017</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>Databricks</td>\n",
       "      <td>2500</td>\n",
       "      <td>0</td>\n",
       "      <td>旧金山</td>\n",
       "      <td>大数据</td>\n",
       "      <td>2013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "      <td>微众银行</td>\n",
       "      <td>2200</td>\n",
       "      <td>200</td>\n",
       "      <td>深圳</td>\n",
       "      <td>金融科技</td>\n",
       "      <td>2014</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9</td>\n",
       "      <td>2</td>\n",
       "      <td>京东科技</td>\n",
       "      <td>2000</td>\n",
       "      <td>0</td>\n",
       "      <td>北京</td>\n",
       "      <td>数字科技</td>\n",
       "      <td>2013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10</td>\n",
       "      <td>11</td>\n",
       "      <td>Checkout.com</td>\n",
       "      <td>1900</td>\n",
       "      <td>870</td>\n",
       "      <td>伦敦</td>\n",
       "      <td>金融科技</td>\n",
       "      <td>2012</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     0     1             2          3            4    5     6     7\n",
       "0   排名  排名变化            企业  价值（亿元人民币）  价值变化（亿元人民币）   总部    行业  成立年份\n",
       "1    1     0            抖音      13400       -10050   北京  社交媒体  2012\n",
       "2    2     1        SpaceX       8400         1680  洛杉矶    航天  2002\n",
       "3    3    -1          蚂蚁集团       8000        -2010   杭州  金融科技  2014\n",
       "4    4     0        Stripe       4100        -2230  旧金山  金融科技  2010\n",
       "5    5    11         Shein       4000         2680   广州  电子商务  2012\n",
       "6    6    15            币安       3000         2010  马耳他   区块链  2017\n",
       "7    7     1    Databricks       2500            0  旧金山   大数据  2013\n",
       "8    8     3          微众银行       2200          200   深圳  金融科技  2014\n",
       "9    9     2          京东科技       2000            0   北京  数字科技  2013\n",
       "10  10    11  Checkout.com       1900          870   伦敦  金融科技  2012"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_html('https://hurun.net/zh-CN/Info/Detail?num=L9SQPH9FKJB1')[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "97156b49",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-03-02T02:55:07.606341Z",
     "start_time": "2023-03-02T02:55:02.615321Z"
    }
   },
   "outputs": [],
   "source": [
    "pd.read_html('https://hurun.net/zh-CN/Info/Detail?num=L9SQPH9FKJB1')[0].to_excel('output_hurun.xlsx')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "165px"
   },
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
